/**
 * @file addr.h
 * Interface for the <b>Addr<b/> class.
 */
#ifndef _ADDR_H
#define _ADDR_H

#include <stdio.h>

#include <arpa/inet.h> // inet_aton(), htons()

#define P2P_ADDR_SIZE (8) // 8 bytes, see P2P3TC, page 2
/**
 * @struct
 * The data structure that holds an Addr.
 */
typedef struct _Addr Addr;

Addr *addr_new();
void addr_delete(Addr **addr);
void addr_cpy(Addr *dst, const Addr *src);
Addr *addr_dup(const Addr *addr);
Addr *addr_set(Addr *addr, const char *ip_str, int tcp_port, int udp_port);
Addr *addr_set_str(Addr *addr, const char *str);
int addr_cmp(const Addr *addr1, const Addr *addr2);
char *addr_get_ip(const Addr *addr);
int addr_get_tcp_port(const Addr *addr);
int addr_get_udp_port(const Addr *addr);
char *addr_get_str(const Addr *addr);
int addr_is_bcast(const Addr *addr);
const Addr *addr_bcast();
void addr_read(Addr *addr, const char *str);
void addr_write(const Addr *addr, char *str);
//TODO: change API according to needs

/**
 * @internal
 * The fields are stored in network order.
 * In order to serialize an Addr, a simple memcpy of the Addr structure will suffice.
 */
struct _Addr {
	struct in_addr ip;
	uint16_t tcp_port;
	uint16_t udp_port;
};

#endif /* _ADDR_H */
